<?php
/**
 * file starwallcontroller.php
 * Created on 2015-4-14 下午9:25:19 
 * Create by xiweijie
 */
namespace haibao\cms\business\control\pc\channel\fashion;

use haibao\cms\business\control\PublicController;
use haibao\cms\business\control\PublicController as PublicControllerBusiness;
use \haibao\cms\business\control\ArticleController as ArticleController;
use \haibao\cms\business\Brand as BrandBusiness;

class StarWallController extends \haibao\cms\business\control\pc\channel\ChannelController{
    
    public function __construct($updateTime = null,$controlId,$isPublish){
        $this->savaLog();
        parent::__construct($updateTime,$controlId,$isPublish);
    }
    
    /**
     * 显示模版内容（模版动态数据的绑定和模版输出）
     * @param : String $content
     * @param : Array $controlData;
     */
    public function displayTemplateHtml(){
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $path = $this->generateHtmlPath(__CLASS__);
        $parameters = array();
        if($controlData['auto']){
            $temp = array();
            foreach($controlData['auto'] as $data){
                $parameterValue = json_decode($data['ParameterValue']);
                array_push($parameters,$parameterValue);
            }
        }
        $isLike = 0;
        $limit = 3;
        if($controlData['manual']){
        	$isLike = $controlData['manual']['isLike'];
        	$limit = $controlData['manual']['limit'];
        }
        $this->assign('parameters', $parameters);
        $publicController = new PublicController();
        list($articleList,$celebritys,$starUrlArr) = $publicController->getArticleIdByStarType($limit,$isLike);
        $celebrityList = array();
        foreach($celebritys as $key=>$celebrity){
            $tagId = $celebrity->TagId;
            $celebrityList[$key]['StarUrl'] = $starUrlArr[$tagId];
            $celebrityList[$key]['Name_CN'] = $celebrity->NameCn;
            $celebrityList[$key]['StarId'] = $celebrity->Id;
            $celebrityList[$key]['Name_EN'] = $celebrity->NameEn;
            $celebrityList[$key]['Birthday'] = $celebrity->Birthday;
            $celebrityList[$key]['XingZuo'] = $celebrity->CelebrityInfo->XingZuo;
            $celebrityList[$key]['FansCount'] = $celebrity->CelebrityRiseCount->FansCount;
            $celebrityList[$key]['ImageUrl'] = $celebrity->CelebrityImage->ImageUrl->Filename;
            if(isset($articleList[$key])){
                $celebrityList[$key]['ArticleProImage'] = $articleList[$key]->ArticleProImage;
                $celebrityList[$key]['Title'] = $articleList[$key]->Title;
                $celebrityList[$key]['ArticleId'] = $articleList[$key]->ArticleTag->ArticleId;
                $celebrityList[$key]['ShortTitle'] = $articleList[$key]->ShortTitle;
                $celebrityList[$key]['ArticleUrl'] = self::getArticleUrl($articleList[$key]->PublishId);
            }else{
                $celebrityList[$key]['ArticleProImage'] = $celebrity->CelebrityImage->ImageUrl->Filename;
                $celebrityList[$key]['Title'] = $celebrity->NameCn;
                $celebrityList[$key]['ShortTitle'] = $celebrity->NameCn;
                $celebrityList[$key]['ArticleUrl'] = $starUrlArr[$tagId];
                $celebrityList[$key]['ArticleId'] = 0;
            }
        }
        $starAreaAndPosition = $this->getAreaAndPosition(2);//明星所在地区，明星分类
        $this->assign('attentionType',\haibao\www\model\data\Favorite::ATTENTION_TYPE_STAR);
        $this->assign('iMarkType',\haibao\www\model\data\Favorite::ID_TYPE_AID_NUM);
        $this->assign('starUrlArr', $starUrlArr);
        $this->assign('celebrityList', $celebrityList);
        $this->assign('starPosition', $starAreaAndPosition);
        $this->assign('starsUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_STARS));
        $this->generateHtml($path,$content);
        $content = $this->getHtml($path);
        $content = $this->replaceCDNLink($content);
        return $content;
    }
    
    /**
     *
     * @param int $type
     * 类型 1:品牌, 2:明星
     */
    private function getAreaAndPosition($type=1){
    	$data=array();
    	$articleControl = ArticleController::initArticleControl();
    	$brandBusiness = new BrandBusiness();
    	if($type==1){
    		$data['Region'] = \haibao\cms\business\Brand::$brandProperty;
    		$data['Place'] = \haibao\cms\business\Brand::$brandRegion;
    	}else{
    		$data['Region'] = \haibao\cms\Config::$starTypesArr;
    		$data['Place'] = \haibao\cms\Config::$placeArr;
    	}
    	return $data;
    }
}